package com.xinjun.kingstar.ui.fragments.home.child.tabs;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import com.hengjun.kingstar.sdk.base.BasePresenter;
import com.hengjun.kingstar.sdk.base.fragment.BaseRecycleFragment;
import com.xinjun.kingstar.R;
import com.xinjun.kingstar.contract.home.tabs.ZhiXunContract;
import com.xinjun.kingstar.presenter.home.tabs.ZhiXunPresenter;
import com.zhouwei.mzbanner.MZBannerView;
import com.zhouwei.mzbanner.holder.MZHolderCreator;
import com.zhouwei.mzbanner.holder.MZViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.Unbinder;

/**
 * Created by SC-02 on 2018/9/19.
 * 最新资讯fragment
 */

public class ZhiXunFragment extends BaseRecycleFragment<ZhiXunContract.ZhiXunPresenter> implements ZhiXunContract.IZhihuView {

    @BindView(R.id.my_banner)
    MZBannerView myBanner;
    Unbinder unbinder;

    public static ZhiXunFragment newInstance() {
        return new ZhiXunFragment();
    }

    @NonNull
    @Override
    public BasePresenter initPresenter() {
        return ZhiXunPresenter.newINstance();
    }

    @Override
    public void updateContentList(List<Object> list) {

    }

    @Override
    public void itemNotifyChanged(int position) {

    }

    @Override
    public void showNetworkError() {

    }

    @Override
    public void showLoadMoreError() {

    }

    @Override
    public void showNoMoreData() {

    }

    @Override
    protected void onErrorViewClick(View view) {

    }

    @Override
    protected void showLoading() {

    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_zixun;
    }

    @Override
    public void initUI(View view, @Nullable Bundle savedInstanceState) {
        // 设置数据(假的)
       List<Integer> list = new ArrayList<>();
        list.add(0,R.drawable.img_banner_1);
        list.add(1,R.drawable.img_banner_1);
        list.add(2,R.drawable.img_banner_1);
        myBanner.setPages(list, new MZHolderCreator<BannerViewHolder>() {
            @Override
            public BannerViewHolder createViewHolder() {
                return new BannerViewHolder();
            }
        });
    }
    //banner设配器以后写到外面去
     class BannerViewHolder implements MZViewHolder<Integer> {
        private ImageView mImageView;
        @Override
        public View createView(Context context) {
            // 返回页面布局
            View view = LayoutInflater.from(context).inflate(R.layout.banner_item,null);
            mImageView = view.findViewById(R.id.banner_image);
            return view;
        }

        @Override
        public void onBind(Context context, int position, Integer data) {
            // 数据绑定
            mImageView.setImageResource(data);
        }
    }

    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {
        super.onLazyInitView(savedInstanceState);
    }

    @Override
    public void onPause() {
        super.onPause();
        myBanner.pause();//暂停轮播
    }

    @Override
    public void onResume() {
        super.onResume();
        myBanner.start();//开始轮播
    }
}
